package jmine.tec.hydra.domain.senderRegistry;

import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Transient;

import jmine.tec.hydra.send.Sender;
import jmine.tec.hydra.send.impl.script.ScriptSender;
import jmine.tec.persist.annotation.DiscriminatorComment;
import jmine.tec.persist.annotation.Index;
import jmine.tec.script.persistent.domain.Script;
import bancosys.tec.component.Documentation;

/**
 * Armazena o registro de um script sender
 * 
 * @author jrenaut
 */
@Entity
@DiscriminatorValue(value = "3")
@DiscriminatorComment("REGISTRO PARA SCRIPT")
public class ScriptSenderRegistry extends AbstractSenderRegistry {

    private Script dispatchScript;

    /**
     * {@inheritDoc}
     */
    @Override
    @Transient
    public Sender getSender() {
        return new ScriptSender(this);
    }

    /**
     * @return the dispatchScript
     */
    @Index(suffix = "JT_0")
    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "COD_HYDRA_SCRIPT_DISPATCH")
    @Documentation("CODIGO DO SCRIPT PARA DISPATCH DA MENSAGEM.")
    public Script getDispatchScript() {
        return this.dispatchScript;
    }

    /**
     * @param dispatchScript the dispatchScript to set
     */
    public void setDispatchScript(Script dispatchScript) {
        this.dispatchScript = dispatchScript;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String toString() {
        return "ScriptSenderRegistry: " + this.dispatchScript.getDescricao() == null ? this.dispatchScript.getMnemonico()
                : this.dispatchScript.getDescricao();
    }

}
